package com.novax.ex.activity.provider.service;

import com.novax.ex.activity.infrastructure.entity.MallPrizeMemos;
import com.novax.ex.activity.infrastructure.mapper.MallPrizeMapper;
import com.novax.ex.activity.infrastructure.mapper.MallPrizeMemosMapper;
import com.novax.ex.common.base.BaseMapper;
import com.novax.ex.common.base.BaseService;
import com.novax.ex.common.enums.MallPrizeMemosOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import jakarta.annotation.Resource;

/**
 * Description: 奖池商品备注信息日志
 *
 * @author Deucalion@novax.email
 * @date 2023/4/3 12:22
 */
@Service
@Slf4j
public class MallPrizeMemosService extends BaseService {
    @Resource
    private MallPrizeMemosMapper mallPrizeMemosMapper;
    @Resource
    private MallPrizeMapper mallPrizeMapper;
    @Override
    protected BaseMapper getBaseMapper() {
        return mallPrizeMemosMapper;
    }

    /** 指定中奖人 */
    @Transactional
    public boolean appoint(Long adminId, Long userId, Long mallPrizeId) {
        // 订单信息变更
        mallPrizeMapper.appoint(mallPrizeId,userId);
        // 记录变更日志
        MallPrizeMemos prizeMemos = new MallPrizeMemos();
        prizeMemos.setCreator(adminId);
        prizeMemos.setUserId(userId);
        prizeMemos.setMallPrizeId(mallPrizeId);
        prizeMemos.setOperationType(MallPrizeMemosOperation.appoint.getStatus());
        return mallPrizeMemosMapper.insertSelective(prizeMemos) > 0;
    }

    /** 取消指定中将人 */
    public boolean cancelAppoint(Long adminId, Long mallPrizeId) {
        // 订单信息变更
        mallPrizeMapper.cancelAppoint(mallPrizeId);
        // 记录变更日志
        MallPrizeMemos prizeMemos = new MallPrizeMemos();
        prizeMemos.setCreator(adminId);
        prizeMemos.setMallPrizeId(mallPrizeId);
        prizeMemos.setOperationType(MallPrizeMemosOperation.cancelAppoint.getStatus());
        return mallPrizeMemosMapper.insertSelective(prizeMemos) > 0;
    }
}
